﻿using ApplicationModels.A02.Identities;
using ApplicationModels.A06.Socializes;
using Commons.Responses;
using EntityModels.E06.Socializes;
using IApplicationServices;
using Microsoft.AspNetCore.Mvc;

namespace WebAPI.Controllers
{
    [Route("[controller]/[action]")]
    public class FollowController : BaseController<int, Follow, FollowAM>
    {
        private readonly IFollowService _followService;
        public FollowController(IFollowService apiService) : base(apiService)
        {
            _followService = apiService;
        }
        /// <summary>
        /// 取消关注
        /// </summary>
        /// <param name="followerId"></param>
        /// <returns></returns>
        
        [HttpDelete]
        public async Task<MessageResponse> UnFollowAsync(string followerId)
        {
            return await _followService.UnFollow(AppUserId, followerId);
        }


        public override Task<MessageResponse> AddAsync(FollowAM apiEntity)
        {
            apiEntity.AppUserId = AppUserId;
            return base.AddAsync(apiEntity);
        }
        /// <summary>
        /// 是否关注
        /// </summary>
        /// <param name="followerId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SingleResponse> IsFollowingAsync(string followerId)
        {
            var res = await _followService.IsFollowingAsync(AppUserId, followerId);
            return new SingleResponse(res);
        }
        /// <summary>
        /// 是否互相关注
        /// </summary>
        /// <param name="followerId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SingleResponse> IsMutuallyFollowingAsync(string followerId)
        {
            var res = await _followService.IsMutuallyFollowingAsync(AppUserId, followerId);
            return new SingleResponse(res);
        }
        /// <summary>
        /// 获取关注列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<DatasResponse<FollowAM>> GetFollowingListAsync(string? userId)
        {
            return await _followService.GetFollowingListAsync(string.IsNullOrEmpty(userId)?AppUserId: userId);
        }
        /// <summary>
        /// 获取粉丝列表
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<DatasResponse<FollowAM>> GetFansListAsync(string? userId)
        {
            return await _followService.GetFansListAsync(string.IsNullOrEmpty(userId) ? AppUserId : userId);
        }
    }
}
